//package com.example.common.utils;
//
//import com.alibaba.fastjson.JSONObject;
//import com.aliyun.tea.TeaException;
//import com.aliyun.facebody20191230.models.*;
//import com.aliyun.teaopenapi.models.Config;
//import com.aliyun.teautil.models.RuntimeOptions;
//import com.drew.metadata.Face;
//
//import java.io.File;
//import java.io.IOException;
//import java.nio.file.Files;
//import java.util.Base64;
//
//public class FaceAuthUtil {
//    private static final String ACCESS_KEY_ID = "your-access-key-id";
//    private static final String ACCESS_KEY_SECRET = "your-access-key-secret";
//
//    // 初始化阿里云客户端
//    private Facebody client() throws Exception {
//        Config config = new Config()
//                .setAccessKeyId(ACCESS_KEY_ID)
//                .setAccessKeySecret(ACCESS_KEY_SECRET)
//                .setRegionId("cn-shanghai"); // 选择地域
//        return new Facebody(config);
//    }
//
//    // 提取人脸特征值（注册时使用）
//    public String extractFaceFeature(String imagePath) throws Exception {
//        File imageFile = new File(imagePath);
//        byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
//
//        // 调用阿里云人脸检测接口
//        DetectFaceRequest request = new DetectFaceRequest()
//                .setImageURL("data:image/jpg;base64," + Base64.getEncoder().encodeToString(imageBytes));
//        DetectFaceResponse response = client().detectFace(request, new RuntimeOptions());
//
//        if (response.getBody() == null || response.getBody().getFaceList().size() == 0) {
//            throw new IllegalArgumentException("未检测到人脸");
//        }
//
//        // 提取特征值（实际为脱敏后的字符串）
//        return response.getBody().getFaceList().get(0).getFaceFeature();
//    }
//}
